<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 校园互助系统</title>
    <style>
        body { background: #f5f5f5; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
        .login-container { max-width: 400px; margin: 80px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); padding: 32px; }
        h2 { text-align: center; color: #4285f4; margin-bottom: 24px; }
        .form-group { margin-bottom: 18px; }
        label { display: block; margin-bottom: 6px; color: #333; }
        input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; }
        button { width: 100%; padding: 10px; background: #4285f4; color: #fff; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; }
        button:hover { background: #3367d6; }
        .link { display: block; text-align: right; margin-top: 10px; color: #4285f4; text-decoration: none; }
        .error { color: #ea4335; text-align: center; margin-bottom: 10px; }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>校园互助系统登录</h2>
        <form id="login-form">
            <div class="form-group">
                <label for="studentId">学号</label>
                <input type="text" id="studentId" name="studentId" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            <div class="error" id="error-msg"></div>
            <button type="submit">登录</button>
        </form>
        <a href="register.html" class="link">没有账号？注册</a>
    </div>
    <script>
        document.getElementById('login-form').addEventListener('submit', function(e) {
            e.preventDefault();
            const studentId = document.getElementById('studentId').value;
            const password = document.getElementById('password').value;
            fetch('/campus-help/api/auth/login', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ studentId, password })
            })
            .then(res => res.json())
            .then(data => {
                if (data.success) {
                    sessionStorage.setItem('user', JSON.stringify(data.user));
                    localStorage.setItem('studentId', data.user.studentId);
                    window.location.href = 'tasks.html';
                } else {
                    document.getElementById('error-msg').innerText = data.message || '登录失败';
                }
            })
            .catch(() => {
                document.getElementById('error-msg').innerText = '网络错误，请稍后再试';
            });
        });
    </script>
</body>
</html> 